package com.good.msgsys.dao;

import com.good.msgsys.entity.User;
import com.good.msgsys.entity.response.UserInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * @author junlong
 * @date 2020/12/31 09:49
 */
public interface UserDao extends JpaRepository<User, String>, JpaSpecificationExecutor<User> {
    // 根据账号account查询用户
    User findByAccount(String account);

    // 查询所有用户，不包含系统管理员,不包含密码
    @Query(value = "select new com.good.msgsys.entity.response.UserInfo(user) from User user where user.role <> ?1 and user.state = ?2",
            countQuery = "select count (user.id) from User user where user.role <> ?1 and user.state = ?2"
    )
    Page<UserInfo> findAllUser(Integer role, Integer state, Pageable pageable);
}
